package com.dj.ms.session;

import cn.hutool.core.lang.Pair;
import com.dj.ms.support.EndpointCollector;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * <br>
 * <p>session管理</p>
 *
 * <br>
 *
 * @author ZJG
 * @version 1.0
 * @date 2021/8/4 上午11:27
 */
@Component
public class SessionCollector implements EndpointCollector {

    private Map<String,Object> sessions = new HashMap<>();

    @Override
    public void collect(Object object) {
        sessions.putIfAbsent((String)((Pair)object).getKey(), ((Pair)object).getValue());
    }

    @Override
    public Object get() {
        return sessions;
    }

    @Override
    public void remove(Object object) {
        this.sessions.remove((String) object);
    }
}
